package Year22_Month06.day20;

import java.util.ArrayList;
import java.util.List;

public class 二叉搜索树的最小绝对差_方法二 {
    public int getMinimumDifference(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        inOrder(root,list);
        int min = Integer.MAX_VALUE;
        for(int i = 0;i < list.size() - 1;i++){
            int key = Math.abs(list.get(i) - list.get(i + 1));
            if(key < min) min = key;
        }
        return min;
    }

    public void inOrder(TreeNode node,List<Integer> list){
        if(node == null) return;
        inOrder(node.left,list);
        list.add(node.val);
        inOrder(node.right,list);
    }
}
